package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteSysUserService;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.domain.SysUserRole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteSysUserFallbackFactory implements FallbackFactory<RemoteSysUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteSysUserService create(Throwable throwable) {

        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSysUserService() {
            @Override
            public AjaxResult add(SysUser sysUser) {
                return AjaxResult.error("新增用户失败" + throwable.getMessage());
            }

            @Override
            public R add(SysUserRole sysUserRole) {
                return R.fail("角色创建失败" + throwable.getMessage());
            }

            @Override
            public SysUser getUserByphone(String phonenumber) {
                SysUser sysUser = new SysUser();
                //失败返回
                return sysUser;
            }
        };
    }
}